<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <link   href="../../resource/layui2.6.8/css/layui.css" rel="stylesheet">
    <script  src="../../resource/js/jquery2.2.js"></script>
    <script  src="../../resource/layui2.6.8/layui.js"></script>
    <script  src="../../resource/layui2.6.8/layui.custom.js"></script>
    <script  src="../../resource/js/action.js"></script>
    <link rel="stylesheet" href="https://res.layuion.com/static/css/global.css?t=1656087836658">
</head>
<body>
<table class="layui-hide" id="rendertable" lay-filter="rendertable"></table>
<script type="text/html" id="toolbar">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add">新建任务</button>
<!--        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="bindAllCompany">工具栏2</button>-->
    </div>
</script>
</body>
<script>
    table.render({
        elem: '#rendertable'
        , url: '/downFileTask/page.do'
        , where: {}
        , response: {
            statusCode: 200 //规定成功的状态码，默认：0
        }
        , parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.records //解析数据列表
            };
        }
        , toolbar: '#toolbar' //开启头部工具栏，并为其绑定左侧模板
        , title: '任务数据'
        , defaultToolbar: false
        , cellMinWidth: 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
        , cols: [[
            {type: 'checkbox', fixed: 'left'}
            , {field: 'taskName', title: '任务名称'}
            , {field: 'targetName', title: '目标网站标题'}
            , {field: 'targetUrl', title: '目标url', sort: true}
            , {field: 'status', title: '任务状态', sort: true,templet:function (row) {
                    if (row.status == 0) {
                        return "解析中"
                    }
                    if (row.status == 1) {
                        return "解析完毕"
                    }
                    if (row.status == 0) {
                        return "解析失败"
                    }
                    return "未知状态"
            }
            }
            , {title: '操作', templet:function (row) {
                    console.log(row)
return `
<a style="color: #1c7430;cursor: pointer;margin: 0 2px" onclick="active.getResourceList(${row.id})">查看资源</a>
<a style="color: #1c7430;cursor: pointer;margin: 0 2px" onclick="active.reAnalysis(${row.id})">重新解析</a>
`
                }}
        ]]
        , page: true,

    });
    var active = {
        reloadTable(){
            table.reload('rendertable')
        },
        add(){
            layer.open({
                type: 2,
                title: "新增任务",
                shadeClose:true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['80%', '80%'],
                btn:["保存"],
                content: "add.html",
                yes:function(index){
                    frameCallback(index,(res)=>{
                        jsonAction("/downFileTask/add.do",res,(res)=>{
                            if (res.code == 200) {
                                layer.msg("保存成功")
                                active.reloadTable()
                            }

                        })
                        console.log(res)
                    })
                    layer.close(index)
                },
            });

        },
        getResourceList(id){
            layer.open({
                type: 2,
                title: "资源列表",
                shadeClose:true,
                shade: false,
                maxmin: true, //开启最大化最小化按钮
                area: ['80%', '80%'],
                btn:["关闭"],
                content: "resourceList.html?id="+id,
                yes:function(index){
                    layer.close(index)
                },
            });
        },
        reAnalysis(id){
            getAction("/downFileTask/reAnalysis.do",{id},(res)=>{
                if (res.code == 200) {
                    layer.msg("解析完毕");
                }
                if (res.code == 500) {
                    layer.msg(res.msg);
                }
            })
        }
    }
    $(".layui-btn").on("click", function () {
        var type = $(this).data("type");
        active[type] ? active[type]() : '';
    })
    table.on('toolbar(rendertable)', function (obj) {
        active[obj.event] ? active[obj.event]() : '';
    })
</script>
</html>